package cn.edu.nuc.crm.service.impl;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.nuc.crm.service.interfaces.RightService;
import cn.edu.nuc.crm.dao.RightMapper;
import cn.edu.nuc.crm.entity.Right;

@Service
public class RightServiceImpl implements RightService {
	@Autowired
	private RightMapper rightMapper;
	
	@Transactional(propagation = Propagation.REQUIRED, // 事务传播行为
			noRollbackFor = { NullPointerException.class }, // 当发生这些异常时,不回滚事务
			rollbackFor = { SQLException.class }, // 当发生这些异常时,回滚事务
			timeout = 20, // 超时. 当此事务耗时达到20秒时,结束此事务
			isolation = Isolation.READ_COMMITTED // 设置隔离级别。 未设置以数据库隔离级别为准
	)
	public Right add(int roleid, int[] ckrr)  throws SQLException	{
		rightMapper.deleteByroleid(roleid);
		   for(int i=0;i<ckrr.length;i++){
			   Right right=new Right();
			   right.setRoleid(roleid);
			   right.setFunid(ckrr[i]);
			   rightMapper.insert(right);		   
		}
		return null;
	}
	
}
